package com.baidu.bos.web.action.staff;

import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.struts2.ServletActionContext;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.baidu.bos.domain.Staff;
import com.baidu.bos.service.IStaffService;
import com.baidu.bos.utils.PageBean;
import com.baidu.bos.web.action.base.BaseAction;

@Controller
@Scope("prototype")
public class StaffAction extends BaseAction<Staff>{
	private int page;
	private int rows;
	@Resource
	private IStaffService staffService;
	
	/**
	 * 添加取派员
	 * @return
	 */
	public String save(){
		staffService.save(model);
		return "list";
	}
	
	
	/**
	 * 分页查询取派员
	 * @throws IOException 
	 */
	public String pageQuery() throws IOException{
		//调用业务层分页查询
		staffService.pageQuery(pageBean);
		this.writeObject2Json(pageBean);
		return NONE;
	}
	
	private String ids;
	public void setIds(String ids) {
		this.ids = ids;
	}
	/**
	 * 将取派员作废
	 * @return
	 */
	@RequiresPermissions("staff-delete")
	public String delete(){
		staffService.delete(ids);
		return "list";
	}
	
	/**
	 * 编辑取派员
	 * @return
	 */
	public String edit(){
		staffService.update(model);
		return "list";
	}
	/**
	 * 查询取派员
	 * @return
	 */
	public String findStaffByAjax(){
		DetachedCriteria dc = DetachedCriteria.forClass(Staff.class);
		//设置查询条件,deltag的值为1
		dc.add(Restrictions.eq("deltag", "0"));
		dc.add(Restrictions.isEmpty("decidedzones"));
		List<Staff> list = staffService.findByContidion(dc);
		//将List数据转化为json对象,写到页面上
		this.writeObject2Json(list);
		return NONE;
	}
	
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public int getRows() {
		return rows;
	}
	public void setRows(int rows) {
		this.rows = rows;
	}
	
}
